package com.base.library.ext

import android.os.Build
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.tabs.TabLayout

object ViewExt {
    /**
     * 去掉长按
     */
    fun BottomNavigationView.clearToast(ids: List<Int>) {
        val bottomNavigationMenuView = getChildAt(0) as? ViewGroup?
        //遍历子View,重写长按点击事件
        bottomNavigationMenuView?.let {
            for (position in ids.indices) {
                it.getChildAt(position).findViewById<View>(ids[position])
                    .setOnLongClickListener { true }
            }
        }
    }

    /**
     * 去掉长按
     */
    fun TabLayout.clearToast() {
        for (i in 0 until tabCount) {
            getTabAt(i)?.let {
                it.view.isLongClickable = false
                // 针对android 26及以上需要设置setTooltipText为null
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                    // 可以设置null也可以是""
                    it.view.tooltipText = null
                }
            }
        }
    }
}